package com.teach.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.dto.ShopOrderDTO;
import com.teach.dto.ShopProductSearch;
import com.teach.entity.Product;
import com.teach.mapper.ProductMapper;
import com.teach.service.shop.ShopGoodsService;
@Service
public class ShopGoodsServiceImpl implements ShopGoodsService{

	@Autowired
	private ProductMapper mapper;
	
	@Override
	public List<Product> listAll() {
		return mapper.selectAll();
	}

	@Override
	public Product get(Long productId) {
		return mapper.selectByPrimaryKey(productId);
	}

	@Override
	public void add(Product product) {
		mapper.insertSelective(product);
		
	}

	@Override
	public void update(Product product) {
		mapper.updateByPrimaryKeySelective(product);
		
	}

	@Override
	public void delete(Long productId) {
		mapper.deleteByPrimaryKey(productId);
		
	}

	@Override
	public List<Product> productList(Long productId) {
		return mapper.selectByID(productId);
	}

	@Override
	public PageInfo<Product> page(ShopProductSearch search) {
		PageInfo<Product> page = PageHelper.startPage(search.getCurrent(), search.getRowMax()).doSelectPageInfo(()->{
			mapper.selects(search);
		});
		return page;
	}

	@Override
	public List<Product> selectByName(String mohuName) {
		return mapper.selectByName(mohuName);
	}

	@Override
	public List<Product> selectByProductID(Long productId) {
		return mapper.selectByProductID(productId);
	}

}
